package com.weetop.aklyscan.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.BaseList;
import com.weetop.aklyscan.bean.MatterRecordListBean;
import com.weetop.aklyscan.bean.OutRecordListBean;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BoxPeijianRecordDetailActivity extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.txt_title)
    TextView txt_title;
    @BindView(R.id.tv_ck_time)
    TextView form1View;
    @BindView(R.id.tv_ck_num)
    TextView form2View;
    @BindView(R.id.tv_order_sn)
    TextView form3View;
    @BindView(R.id.tv_member_sn)
    TextView form4View;
    private CommonRecyclerAdapter<MatterRecordListBean> adapter;
    private List<MatterRecordListBean> list = new ArrayList<>();

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_out_record);
        ButterKnife.bind(this);
        String start_time = getIntent().getStringExtra("start_time");
        String order_sn = getIntent().getStringExtra("order_sn");
        String order_type = getIntent().getStringExtra("order_type");
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<MatterRecordListBean>(mActivity, R.layout.item_matter_box_record_list, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, MatterRecordListBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                if(order_type.equals("3")){
                    helper.setText(R.id.tv_time, item.getGoods_model());
                    helper.setText(R.id.tv_num, item.getGoods_name());
                    helper.setText(R.id.tv_number, item.getNum());
                }else{
                    helper.setText(R.id.tv_time, item.getSerial_code());
                    helper.setText(R.id.tv_num, item.getGoods_model());
                    helper.setText(R.id.tv_number, item.getGoods_name());
                }

                helper.setText(R.id.tv_member_number, item.getBarcode());
            }
        };
        if(order_type.equals("3")){
            form1View.setText("配件编号");
            form2View.setText("配件名称");
            form3View.setText("数量");
        }else{
            form1View.setText("SN号");
            form2View.setText("产品型号");
            form3View.setText("产品名称");
        }
        form4View.setText("中转箱号");
        txt_title.setText("装箱记录详情");

        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
        mPresenter.Into76(start_time, order_sn);
    }


    @Override
    public void getInto75Success(BaseModel<BaseList<MatterRecordListBean>> o) {
        List<MatterRecordListBean> listBeans = o.getData().getList_data();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
//        totalNumView.setText(o.getData().getCount());
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {

    }
}
